package com.genexususa.eo.facebook.connection;

import com.genexususa.eo.facebook.util.Constants;
import com.genexususa.eo.facebook.util.Info;
import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.types.Account;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class AccountManager {

    public ArrayList<String> getAllAccounts(){

        ArrayList<String> result = new ArrayList<String>();

        try {
            HashMap<String, String> info = Info.getFacebookProperties();

            String accessToken = info.get(Constants.ACCESS_TOKEN);

            FacebookClient client = new DefaultFacebookClient(accessToken);

            Connection<Account> accounts = client.fetchConnection("me/accounts", Account.class);

            for(Account account : accounts.getData()){
                result.add(account.getId());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;

    }

}
